//package com.siecom.packageinterface;
//
//import android.app.Activity;
//import android.bluetooth.BluetoothDevice;
//import android.graphics.Bitmap;
//import android.os.Bundle;
//import android.os.Environment;
//import android.os.Handler;
//import android.os.Message;
//import android.util.Log;
//import android.widget.Toast;
//
//import BankCardInfoBean;
//import IdentityInfoBean;
//import LockMap;
//import ResultLock;
//import ConstDefine;
//import EMVParam;
//import EmvOptions;
//import Base64;
//import ByteTool;
//import EncryptUnit;
//import FingerUnit;
//import StringUtil;
//import ConnectStatusCallback;
//import DeviceCallback;
//import SiecomDevice;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.io.ByteArrayOutputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.lang.reflect.Field;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//
///**
// * @author ronghua.yang
// *
// */
//public class SiecomDevices_218 implements ExternalDeviceEngine {
//	private Activity mActivity;
//
//	public static final int FINGERMAS = 0; // 读取指纹特征码
//	public static final int FINGERBITMAP = 1; // 读取指纹图像
//	public static final int FINGERCP = 2; // 读取指纹特征码与指纹图像
//	public static String Finger = null; // 用来暂时保存指纹特征码;
//
//	public static boolean BluetoothStatus = false;
//	private long startTime;
//
//	public final static int MSG_CONNED = 0; // 连接成功
//	public final static int MSG_CONNING = 1; // 连接中
//	public final static int MSG_NOCONN = 2; // 连接断开
//	public final static int MSG_CANT = 3; // 无法连接
//	public final static int MSG_CLOSE = 4; // 关闭动画
//
//	public static final int IC_CARD = 0x00;// ic卡
//	public final static int MSR_CARD = 0x02;// 磁条卡
//	public final static int PIC_CARD = 0x01;// nfc卡
//	public final static int AUTO_FIND = 0x03;// 自动读取
//
//	final static int ICCar = 1; // 读的是IC卡
//	final static int NFCCar = 2; // 读的是非接卡
//	public static int isCar = 0;
//	public static int keyindex = 0;
//
//	private Handler mHandler;
//	SimpleDateFormat dFormat = new SimpleDateFormat("yyMMddHHmmss");
//
//	private Boolean isDown = true;
//
//	public SiecomDevices_218(Activity mActivity, final Handler mHandler, BluetoothDevice device) {
////		// TODO Auto-generated constructor stub
//		this.mActivity = mActivity;
//		this.mHandler = mHandler;
////		connectBluetooth(localBluetoothDevice);
//
//		SiecomDevice.connectStatusChange(new ConnectStatusCallback() {
//			@Override
//			public void onConnectStart() {
//				Log.e("connectStatusChange", "onConnectStart");
//
//				Message msg = new Message();
//				msg.what = MSG_CONNING;
//				mHandler.sendMessage(msg);
//			}
//
//			@Override
//			public void onConnected() {
//				Log.e("connectStatusChange", "onConnected");
//
//				BluetoothStatus = true;
//				Message msg = new Message();
//				msg.what = MSG_CONNED;
//				mHandler.sendMessage(msg);
//			}
//
//			@Override
//			public void onDisConnect(Throwable e) {
//				Log.e("connectStatusChange", e.getMessage());
//
//				BluetoothStatus = false;
//				Message msg = new Message();
//				msg.what = MSG_NOCONN;
//				mHandler.sendMessage(msg);
////				handler.post(new Runnable() {
////					@Override
////					public void run() {
////						Toast.makeText(DeviceActivity.this, "连接已经断开", Toast.LENGTH_SHORT).show();
////						dismissDialog();
////					}
////				});
//
//
//			}
//		});
//
//		SiecomDevice.startConnect(device, new DeviceCallback() {
//			@Override
//			public void onStart() {
//
//			}
//
//			@Override
//			public void onError(Bundle bundle) {
//
//			}
//
//			@Override
//			public void onSuccess(Bundle bundle) {
//
////				afterLink();
//			}
//
//			@Override
//			public void onCompleted(Bundle bundle) {
//
//
//			}
//		}, true);
//
//	}
//
//	final String amount = "123456.00";// 金额显示,必须至少满6位
//
//	@Override
//	/**
//	 * 读取卡片信息
//	 *
//	 * @param cardType
//	 *            读取类型
//	 * @param outTime
//	 *            超时时间设置
//	 * @param isDownCard
//	 *            是否下电
//	 */
//	public void readCard(int cardType, int outTime, String isDownCard, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//
//		switch (cardType) {
//		case 0:
//			cardType = IC_CARD;
//			break;
//		case 1:
//			cardType = PIC_CARD;
//			break;
//		case 2:
//			cardType = MSR_CARD;
//			break;
//		case 3:
//			cardType = AUTO_FIND;
//			break;
//		default:
//			cardType = AUTO_FIND;
//			break;
//		}
////		CarStatus = cardType;
//		if (isDownCard.equals("true")) {
//			isDown = true;
//		} else if (isDownCard.equals("false")) {
//			isDown = false;
//		}
//
//
//			Log.e("cardType:", cardType + "----");
//			EmvOptions options = new EmvOptions();
//			EMVParam emvParam = new EMVParam();
//			byte[] MerchCateCode = new byte[2];
//			MerchCateCode[0] = 0x00;
//			MerchCateCode[1] = 0x01;
//			emvParam.setMerchCateCode(MerchCateCode);
//			String MerchId = "123456789012345";
//			emvParam.setMerchId(MerchId.getBytes());
//			emvParam.setMerchName("EMV LIBRARY".getBytes());
//			emvParam.setTermId("12345678".getBytes());
//			emvParam.setTerminalType((byte) 0x22);
//			emvParam.setSurportPSESel((byte) 0x01);
//			byte[] Capability = {(byte) 0xE0, (byte) 0x60, (byte) 0xC8};
//			emvParam.setCapability(Capability);
//			byte[] ExCapability = {(byte) 0x60, (byte) 0x00, (byte) 0xF0,
//					(byte) 0x20, (byte) 0x01};
//			emvParam.setExCapability(ExCapability);
//			byte[] CountryCode = {(byte) 0x01, (byte) 0x56};
//			byte[] TransCurrCode = {(byte) 0x01, (byte) 0x56};
//			byte[] ReferCurrCode = {(byte) 0x01, (byte) 0x56};
//			emvParam.setCountryCode(CountryCode);
//			emvParam.setTransCurrCode(TransCurrCode);
//			emvParam.setTransCurrExp((byte) 0x02);
//			emvParam.setReferCurrCode(CountryCode);
//			emvParam.setCL_TransLimit(100000);
//			emvParam.setTransType((byte) 0x00);// 交易类型
//			byte[] TermTransQuali = {0x24, 0x00, 0x00, (byte) 0x80};
//			emvParam.setTermTransQuali(TermTransQuali);
//			emvParam.setCL_bStatusCheck((byte) 0x00);
//			emvParam.setCL_CVMLimit(10000);
//			emvParam.setCL_FloorLimit(20000);
//
//			emvParam.setECTSI((byte) 0x01);
//			emvParam.setEC_TermLimit(10000);
//			emvParam.setEC_bTermLimitCheck((byte) 0x01);
//
//			options.setEmvParam(emvParam);
//			options.setAuthorizedAmount(0);
//
//			SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");// 设置日期格式
//			String time = df.format(new Date());
//			options.setTime(time);
//			options.setTransNo(1);
//
////                String[]   wantTags = new String[]{"5A", "57", "9F26", "9F27", "9F10", "9F37", "9F36",
////                        "95", "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03",
////                        "9F33", "9F34", "9F35", "9F1E", "4F", "5F34"};
//			String[] wantTags = {"5A", "57", "5F20", "9F62", "9F61", "9F1F", "9F79",
//					"9F77", "5F24", "5F34", "9F26", "9F27", "9F10", "9F37", "9F36",
//					"95", "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33",
//					"9F34"};
//			SiecomDevice.readBankCard(cardType, new DeviceCallback() {
//				@Override
//				public void onStart() {
////					cardTypeText.setText("");
////					cardNoText.setText("");
////					cardInfoText.setText("");
//////                        speaker.speak("please swipe or insert your card");
////					Snackbar.make(view, getResources().getString(R.string.checkCard), Snackbar.LENGTH_LONG).setAction("Action", null).show();
////					now = System.currentTimeMillis();
//				}
//
//				@Override
//				public void onError(Bundle bundle) {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
//
//					JSONObject json = new JSONObject();
//				try {
//					int code = bundle.getInt("code");
//					String msg = bundle.getString("message");
//					json.put("code", code);
//					json.put("message", msg);
//					Log.e("GJ","IC卡数据"+ json.toString());
//					callbackContext.error(json.toString());
//					closeDialog();
////					LogUtil.info("msg", "error msg:" + msg);
//
//					// IC卡下电
//					// SiecomDevice.shutDownCard();
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
//
//					//speaker.speak("error：" + code);
//
////					Snackbar.make(view, "err:" + code + "--" + msg, Snackbar.LENGTH_LONG).setAction("Action", null).show();
//				}
//
//				@Override
//				public void onSuccess(Bundle bundle) {
//
//					final BankCardInfoBean bean = bundle.getParcelable("data");
//					long finish = System.currentTimeMillis();
////					Snackbar.make(view, getResources().getString(R.string.readComplete) + ":useTime:" + (finish - now) + "ms", Snackbar.LENGTH_LONG).setAction("Action", null).show();
////					if (bean.cardType == ConstDefine.IC_CARD) {
//////						cardTypeText.setText(getResources().getString(R.string.ICC));
//////						cardNoText.setText(bean.cardNo);
//////						cardInfoText.setText(bean.ICChipData);
////
////					} else if (bean.cardType == ConstDefine.PIC_CARD) {
////
//////						cardTypeText.setText(getResources().getString(R.string.PICC));
//////						cardNoText.setText(bean.cardNo);
//////						cardInfoText.setText(bean.ICChipData);
////
////					} else if (bean.cardType == ConstDefine.MSR_CARD) {
//////						cardTypeText.setText(getResources().getString(R.string.MSR));
//////						cardNoText.setText(bean.cardNo);
//////						cardInfoText.setText(bean.oneMagneticTrack + "\r\n" + bean.twoMagneticTrack + "\r\n" + bean.threeMagneticTrack);
////
////					}
//
//
//						if (bean.cardType == IC_CARD) {
//							isCar = ICCar;
//						} else if (bean.cardType == PIC_CARD) {
//							isCar = NFCCar;
//						} else if (bean.cardType == MSR_CARD) {
//							String carNo = bean.cardNo;
////							LogUtil.info("msg", "carNos:" + carNo);
//							if (carNo.substring(0, 2).indexOf("18") != -1||carNo.substring(0, 2).indexOf("14") != -1) {
//								bean.cardType = 3;
//								carNo = carNo.substring(2);
//							} else if (carNo.indexOf("88888888") != -1) {
//								bean.cardType = 4;
//								carNo = carNo.substring(8, 16);
//							}
//							bean.cardNo = carNo;
////							LogUtil.info("msg", "carNo:" + carNo
////									+ "---cardType:" + bean.cardType);
//						}
//						JSONObject json = null;// 将java对象转换为json对象
//						try {
////							long finish = System.currentTimeMillis();
//							long elapsedTime = finish - startTime;
//							json = Util.fromObjToJson(bean);
//							json.put("time", elapsedTime);
//							if (bean.ICChipData != null
//									&& !bean.ICChipData.equals("")) {
//								json.put(
//										"Serialnum",
//										"0"
//												+ StringUtil.tagParse("5F34",
//														bean.ICChipData));
//								json.put("Money", StringUtil.tagParse("9F79",
//										bean.ICChipData));
//							}
//							String str = json.toString();// 将json对象转换为字符串
//							Log.e("GJ","IC卡数据"+ str);
//							callbackContext.success(str);
//							closeDialog();
////							LogUtil.info("msg", str);
//							// IC卡下电
//							if (isDown) {
//								/*Toast.makeText(mActivity, "IC卡下电了...",
//										Toast.LENGTH_LONG).show();*/
////								LogUtil.info("msg", "IC卡下电了...");
////								SiecomDevice.shutDownCard();
//							}
//						} catch (Exception e) {
//							e.printStackTrace();
//						}
//
//
//					//如果不是磁卡可以获取交易的明细和做arpc
//					if (bean.cardType != ConstDefine.MSR_CARD) {
////						arpcBtn.setVisibility(View.VISIBLE);
////						getLogBtn.setVisibility(View.VISIBLE);
//
////						arpcBtn.setOnClickListener(new View.OnClickListener() {
////							@Override
////							public void onClick(View v) {
////								final String arpc = "910A2501EEC5A3FDBF563030";//91开头，脚本是72开头
////								final String script = "7251860F04DA9F790A000000000000A4B17D6D860F04DA9F770A0000001000008C09E6BF862D04DC010C2870229F61123433313232313139383830373136313231589F6201105F2006C5CBB0D8D3EEA168BB5A";
////
////								cardInfoText.setText("TestARPC:" + arpc + "\r\n" + "TestScript:" + script);
////								SiecomDevice.ARPCExecuteScript(bean.cardType, arpc, script, new DeviceCallback() {
////									@Override
////									public void onStart() {
////
////									}
////
////									@Override
////									public void onError(Bundle bundle) {
////
////										cardInfoText.setText("ARPC 返回:" + bundle.getInt("code") + "\r\n");
////									}
////
////									@Override
////									public void onSuccess(Bundle bundle) {
////
////										cardInfoText.setText("ret:" + bundle.getString("result"));
////
////
////									}
////
////									@Override
////									public void onCompleted(Bundle bundle) {
////
////										arpcBtn.setVisibility(View.VISIBLE);
////
////									}
////								}, 10000, true);
////
////
////							}
////						});
////						getLogBtn.setOnClickListener(new View.OnClickListener() {
////							@Override
////							public void onClick(View v) {
////								//获取交易明细
////								cardInfoText.setText("正在获取交易明细");
////								SiecomDevice.readTradeLog(bean.cardType, new DeviceCallback() {
////									@Override
////									public void onStart() {
////
////										arpcBtn.setVisibility(View.INVISIBLE);
////
////									}
////
////									@Override
////									public void onError(Bundle bundle) {
////
////										final String arpc = "910A2501EEC5A3FDBF563030";//91开头，脚本是72开头
////										final String script = "7251860F04DA9F790A000000000000A4B17D6D860F04DA9F770A0000001000008C09E6BF862D04DC010C2870229F61123433313232313139383830373136313231589F6201105F2006C5CBB0D8D3EEA168BB5A";
////
////										cardInfoText.setText("TestARPC:" + arpc + "\r\n" + "TestScript:" + script);
////
////
////									}
////
////									@Override
////									public void onSuccess(Bundle bundle) {
////										List<TradeLogBean> list = bundle.getParcelableArrayList("data");
////										StringBuffer buf = new StringBuffer();
////										for (TradeLogBean bean : list) {
////
////											LogUtil.e("logbean:", bean.getMerchName());
////											buf.append("交易记录—时间：" + bean.getDate() + bean.getTime() + "—金额:" + bean.getAmount() + "—商户：" + bean.getMerchName() + "\r\n");
////										}
////										cardInfoText.setText("交易明细：\r\n" + buf);
////									}
////
////									@Override
////									public void onCompleted(Bundle bundle) {
////
////									}
////								}, 30000, true);
////
////
////							}
////
////						});
//					} else {
//
////						arpcBtn.setVisibility(View.INVISIBLE);
////						getLogBtn.setVisibility(View.INVISIBLE);
//					}
//
//
//				}
//
//				@Override
//				public void onCompleted(Bundle bundle) {
//
//				}
//
//			}, options,wantTags, outTime, true);
//
//
//
//
//
////		EmvOptions options = new EmvOptions();
////		String time = dFormat.format(new Date());// 交易时间，年月日时分秒 2015为15
////													// 直接传入java生成的即可
////		options.setTime(time);
////		byte[] MerchCateCode = new byte[2];
////		MerchCateCode[0] = 0x00;
////		MerchCateCode[1] = 0x01;
////		options.setMerchCateCode(MerchCateCode);
////		String MerchId = "123456789012345";
////		options.setMerchId(MerchId.getBytes());
////		options.setMerchName("EMV LIBRARY".getBytes());
////		options.setTermId("12345678".getBytes());
////		options.setTerminalType((byte) 0x22);
////		options.setSupportPSESel((byte) 0x01);
////		byte[] Capability = { (byte) 0xE0, (byte) 0xC0, (byte) 0xC8 };
////		options.setCapability(Capability);
////		byte[] ExCapability = { (byte) 0x60, (byte) 0x00, (byte) 0xF0, (byte) 0x20, (byte) 0x01 };
////		options.setExCapability(ExCapability);
////		byte[] CountryCode = { (byte) 0x01, (byte) 0x56 };
////		options.setCountryCode(CountryCode);
////		options.setTransCurrCode(CountryCode);
////		options.setTransCurrExp((byte) 0x02);
////		options.setReferCurrCode(CountryCode);
////		options.setCL_TransLimit(100000);
////		options.setTransType((byte) 0x30);// 交易类型
////
////		byte[] TermTransQuali = { 0x24, 0x00, 0x00, (byte) 0x80 };
////		options.setTermTransQuali(TermTransQuali);
////		options.setCL_bStatusCheck((byte) 0x00);
////		options.setCL_CVMLimit(10000);
////		options.setCL_FloorLimit(20000);
////		options.setTransNo(1);// 交易号 可以不用设置，默认1；
////
////		String[] tags = { "5A", "57", "9F26", "9F27", "9F10", "9F37", "9F36", "95", "9A03", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33",
////				"9F34", "9F35", "9F1E", "84", "9F09", "9F41", "9F63", "5F34", "9A" };
////		options.setTags(tags);// 设置要获取的标签类型 要读取卡号必须保证有5A和57的标签
////		SiecomDevice.ReadBankCard(cardType, options, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				/**
////				 * 这里可以提示插入卡片
////				 */
////				startTime = System.currentTimeMillis();
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				final BankCardInfoBean bean = bundle.getParcelable("data");
////
////
////						if (bean.cardType == BankCardModule.IC_CARD) {
////							isCar = ICCar;
////						} else if (bean.cardType == BankCardModule.PIC_CARD) {
////							isCar = NFCCar;
////						} else if (bean.cardType == BankCardModule.MSR_CARD) {
////							String carNo = bean.cardNo;
////							LogUtil.info("msg", "carNos:" + carNo);
////							if (carNo.substring(0, 2).indexOf("18") != -1||carNo.substring(0, 2).indexOf("14") != -1) {
////								bean.cardType = 3;
////								carNo = carNo.substring(2);
////							} else if (carNo.indexOf("88888888") != -1) {
////								bean.cardType = 4;
////								carNo = carNo.substring(8, 16);
////							}
////							bean.cardNo = carNo;
////							LogUtil.info("msg", "carNo:" + carNo
////									+ "---cardType:" + bean.cardType);
////						}
////						JSONObject json = null;// 将java对象转换为json对象
////						try {
////							long finish = System.currentTimeMillis();
////							long elapsedTime = finish - startTime;
////							json = Util.fromObjToJson(bean);
////							json.put("time", elapsedTime);
////							if (bean.ICChipData != null
////									&& !bean.ICChipData.equals("")) {
////								json.put(
////										"Serialnum",
////										"0"
////												+ StringUtil.tagParse("5F34",
////														bean.ICChipData));
////								json.put("Money", StringUtil.tagParse("9F79",
////										bean.ICChipData));
////							}
////							String str = json.toString();// 将json对象转换为字符串
////							callbackContext.success(str);
////							closeDialog();
////							LogUtil.info("msg", str);
////							// IC卡下电
////							if (isDown) {
////								/*Toast.makeText(mActivity, "IC卡下电了...",
////										Toast.LENGTH_LONG).show();*/
////								LogUtil.info("msg", "IC卡下电了...");
////								SiecomDevice.shutDownCard();
////							}
////						} catch (Exception e) {
////							e.printStackTrace();
////						}
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					closeDialog();
////					LogUtil.info("msg", "error msg:" + msg);
////
////					// IC卡下电
////					// SiecomDevice.shutDownCard();
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		}, outTime);
//
//	}
//
//	@Override
//	/**
//	 * 读取身份证信息
//	 *
//	 * @param outTime
//	 *            超时时间设置
//	 */
//	public void readIdCard(int outTime, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//
//
//		DeviceCallback taskCallback = new DeviceCallback() {
//			@Override
//			public void onStart() {
//
//			}
//
//			@Override
//			public void onSuccess(Bundle bundle) {
//				IdentityInfoBean bean = bundle.getParcelable("data");
//				JSONObject json = null;
//				long finish = System.currentTimeMillis();
//				long elapsedTime = finish - startTime;
//				try {
//					json = Util.fromObjToJson(bean);
//					json.put("time", elapsedTime);
//					json.put("photo", Util.bitmapToStr(bean.icon));
//					if (bean.fingerByte != null) {
//						json.put("finger", ByteTool.byte2hex(bean.fingerByte));
//					}
//					String str = json.toString();// 将json对象转换为字符串
//					Log.e("GJ","数据都是"+str );
//					callbackContext.success(str);
//					closeDialog();
//					Log.v("msg", str);
//
////					LogUtil.info("msg", "success!!!!");
//
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//
//			@Override
//			public void onCompleted(Bundle bundle) {
//
//
//			}
//
//			@Override
//			public void onError(Bundle bundle) {
//				JSONObject json = new JSONObject();
//				try {
//					int code = bundle.getInt("code");
//					String msg = bundle.getString("message");
//					json.put("code", code);
//					json.put("message", msg);
//					callbackContext.error(json.toString());
//					closeDialog();
////					LogUtil.info("msg", "error");
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
//			}
//		};
//		SiecomDevice.readIdentityCard(taskCallback, outTime, true);
//
////		SiecomDevice.ReadIdentity(true, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				startTime = System.currentTimeMillis();
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				IdentityInfoBean bean = bundle.getParcelable("data");
////				JSONObject json = null;
////				long finish = System.currentTimeMillis();
////				long elapsedTime = finish - startTime;
////				try {
////					json = Util.fromObjToJson(bean);
////					json.put("time", elapsedTime);
////					json.put("photo", Util.bitmapToStr(bean.icon));
////					if (bean.fingerByte != null) {
////						json.put("finger", ByteTool.byte2hex(bean.fingerByte));
////					}
////					String str = json.toString();// 将json对象转换为字符串
////					callbackContext.success(str);
////					closeDialog();
////					LogUtil.v("msg", str);
//////					LogUtil.info("msg", "success!!!!");
////
////				} catch (Exception e) {
////					e.printStackTrace();
////				}
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					closeDialog();
////					LogUtil.info("msg", "error");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		}, outTime);
//	}
//
//	@Override
//	/**
//	 * IC卡写卡
//	 *
//	 * @param ARPC
//	 *            服务器传送的ARPC
//	 * @param ScriptStr
//	 *            服务器传送的执行脚本
//	 * @param callbackContext
//	 */
//	public void writeARPCCard(String ARPC, String ScriptStr, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
////		LogUtil.info("GJ", "ARPC" + ARPC + "  ScriptStr" + ScriptStr);
//		final JSONObject json = new JSONObject();
//		if (ARPC == null || ARPC.equals("")) {
//			try {
//				json.put("code", -1);
//				json.put("message", "ARPC不能为空");
//				callbackContext.error(json.toString());
////				LogUtil.info("msg", "error");
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//
//		} else {
//
//			ARPC = ARPC + "3030";
//
//
//			SiecomDevice.ARPCExecuteScript(isCar, ARPC, ScriptStr, new DeviceCallback() {
//				@Override
//				public void onStart() {
//
//				}
//
//				@Override
//				public void onError(Bundle bundle) {
//					try {
//						// 成功校验ARPC 和写入脚本
//						json.put("Result", "脚本执行成功");
//						json.put("error",bundle.getString("result"));
//					} catch (Exception e) {
//						// TODO: handle exception
//					}
////					cardInfoText.setText("ret:" + bundle.getString("result"));
//					String str = json.toString();// 将json对象转换为字符串
//					callbackContext.success(str);
//
////					cardInfoText.setText("ARPC 返回:" + bundle.getInt("code") + "\r\n");
//				}
//
//				@Override
//				public void onSuccess(Bundle bundle) {
//					try {
//						// 成功校验ARPC 和写入脚本
//						json.put("Result", "脚本执行成功");
//					} catch (Exception e) {
//					// TODO: handle exception
//					}
////					cardInfoText.setText("ret:" + bundle.getString("result"));
//					String str = json.toString();// 将json对象转换为字符串
//					callbackContext.success(str);
//
//				}
//
//				@Override
//				public void onCompleted(Bundle bundle) {
//
////					arpcBtn.setVisibility(View.VISIBLE);
//
//				}
//			}, 10000, true);
//
////			BankCardModule mEmvModule = BankCardModule.getInstance();
////			byte[] ScriptResult = new byte[256];
////			byte[] TC = new byte[256];
////			// byte[] arpc = ByteTool.hexStr2Bytes(ARPC);
////			// byte[] Script = ByteTool.hexStr2Bytes(ScriptStr);
////
////			// mEmvModule.useEmvLibGet();
////			if (isCar == ICCar) {
////				mEmvModule.ARPCExecuteScript(0x00, ARPC, ScriptStr, ScriptResult, TC);
////			} else if (isCar == NFCCar) {
////				mEmvModule.ARPCExecuteScript(0x01, ARPC, ScriptStr, ScriptResult, TC);
////			}
////			String scriptResultSting = new String(ScriptResult).trim();
////			// String scriptResultSting = "DF310800 00 05 20 00 0";
////			// LogUtil.e("GJ", "脚本返回结果"+new String (ScriptResult).trim());
////			if (scriptResultSting != null && !scriptResultSting.equals("")) {
////				scriptResultSting = scriptResultSting.substring(6, 8);
////				try {
////					if (scriptResultSting.equals("00") || scriptResultSting.equals("20")) {
////						// 成功校验ARPC 和写入脚本
////						json.put("Result", "脚本执行成功");
////					} else {
////						// 校验ARPC 和写入脚本失败
////						json.put("Result", "脚本执行失败");
////					}
////				} catch (Exception e) {
////					// TODO: handle exception
////				}
////			}
////
////			String str = json.toString();// 将json对象转换为字符串
////			callbackContext.success(str);
////			LogUtil.info("msg", str);
////			// IC卡下电
////			SiecomDevice.shutDownCard();
//		}
//	}
//
//	/**
//	 * IC卡校验
//	 *
//	 * @param ARPC
//	 *            服务器传送的ARPC
//	 * @param callbackContext
//	 */
//
//	public void checkARPC(String ARPC, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//
//		final JSONObject json = new JSONObject();
//		if (ARPC == null || ARPC.equals("")) {
//			try {
//				json.put("code", -1);
//				json.put("message", "ARPC不能为空");
//				callbackContext.error(json.toString());
////				LogUtil.info("msg", "error");
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//
//		} else {
////			BankCardModule mEmvModule = BankCardModule.getInstance();
//			ARPC = ARPC + "3030";
//			SiecomDevice.ARPCExecuteScript(isCar, ARPC, "", new DeviceCallback() {
//				@Override
//				public void onStart() {
//
//				}
//
//				@Override
//				public void onError(Bundle bundle) {
//					try {
//						// 成功校验ARPC 和写入脚本
//						json.put("Result", "脚本执行成功");
//						json.put("error",bundle.getString("result"));
//					} catch (Exception e) {
//						// TODO: handle exception
//					}
////					cardInfoText.setText("ret:" + bundle.getString("result"));
//					String str = json.toString();// 将json对象转换为字符串
//					callbackContext.success(str);
//
////					cardInfoText.setText("ARPC 返回:" + bundle.getInt("code") + "\r\n");
//				}
//
//				@Override
//				public void onSuccess(Bundle bundle) {
//					try {
//						// 成功校验ARPC 和写入脚本
//						json.put("Result", "脚本执行成功");
//					} catch (Exception e) {
//						// TODO: handle exception
//					}
////					cardInfoText.setText("ret:" + bundle.getString("result"));
//					String str = json.toString();// 将json对象转换为字符串
//					callbackContext.success(str);
//
//				}
//
//				@Override
//				public void onCompleted(Bundle bundle) {
//
////					arpcBtn.setVisibility(View.VISIBLE);
//
//				}
//			}, 10000, true);
//		}
//	}
//
//	public int setEncrypt() {
//		int endType = 0;
//		int mkeyIndex = 0;
//		int wkeyIndex = 0;
//		final long messageId = System.currentTimeMillis();
//		SiecomDevice.keySetEncryptMode(ConstDefine.KEY_3DES,endType,mkeyIndex,wkeyIndex, new DeviceCallback() {
//			@Override
//			public void onStart() {
//
//			}
//
//			@Override
//			public void onError(Bundle bundle) {
//				int code = bundle.getInt("code");
//				String msg = bundle.getString("message");
//
//
////                Toast.makeText(DeviceActivity.this, "err:" + code + "--" + msg, Toast.LENGTH_SHORT).show();
//			}
//
//			@Override
//			public void onSuccess(Bundle bundle) {
//				ResultLock lock = LockMap.pick(messageId);
//
//				Log.e("GJ","设置加密模式成功");
//				if (lock != null) {
//
//					synchronized (lock) {
//
//						lock.notify();
//						lock.setMessage(0);
//
//					}
//
//				}
////                Toast.makeText(DeviceActivity.this, getResources().getString(R.string.set_encrypt), Toast.LENGTH_SHORT).show();
//			}
//
//			@Override
//			public void onCompleted(Bundle bundle) {
//
//			}
//		}, 3000, false);
//
//		ResultLock r = new ResultLock(messageId);
//		LockMap.store(messageId, r);
//		try {
//			synchronized (r) {
//				r.wait(15000 + 3000);
//			}
//		} catch (Exception ee) {
//			ee.printStackTrace();
//		} finally {
//			LockMap.del(messageId);
//		}
//		return (int) r.getMessage();
//
//	}
//
//	/**
//	 * 更新密钥
//	 *
//	 * @param mainkey
//	 *            密钥校验值
//	 * @param pinValue
//	 *            主密钥密文
//	 * @param callbackContext
//	 */
//	@Override
//	public void updateMainKey(String mainkey, final String pinValue, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//
//		final JSONObject json = new JSONObject();
//
//		setEncrypt();
//		final long messageId = System.currentTimeMillis();
////        String mkeyIndex = String.format("%02d", ZmkIndex);
////		String mkeyIndex = "0x"+DecimalConVer(ZmkIndex);
////		if(ZmkIndex < 10){
////			mkeyIndex = "0"+DecimalConVer(ZmkIndex);
////		}
//
////		LogUtil.e("ZmkIndex", mkeyIndex);
//
//		SiecomDevice.updateMainKey("01", mainkey.trim(), new DeviceCallback() {
//			@Override
//			public void onStart() {
//
//			}
//
//			@Override
//			public void onError(Bundle bundle) {
//
//				int code = bundle.getInt("code");
//				String msg = bundle.getString("message");
//				try {
//					json.put("Result", "更新主密钥失败");
//					json.put("code", code);
//					json.put("message", msg);
//					callbackContext.error(json.toString());
//				} catch (Exception e) {
//					// TODO: handle exception
//				}
//			}
//
//			@Override
//			public void onSuccess(Bundle bundle) {
//				String check = bundle.getString("data");
//			try {
//				JSONObject mJSO = new JSONObject(check);
//
////				LogUtil.e("GJ","数据是："+mJSO.get("data")+"jianyaozhi:"+pinValue.substring(0,8).trim());
//				check = mJSO.get("data").toString();
//				if (check.trim().equals(pinValue.substring(0,8).trim())) {
//					json.put("Result", "更新主密钥成功");
////					api.Sys_writeSN(pinValue.trim().getBytes());
//					callbackContext.success(json.toString());
//				} else {
//					json.put("Result", "更新主密钥失败");
//					callbackContext.error(json.toString());
//				}
//			} catch (Exception e) {
//				// TODO: handle exception
//			}
//
//				Log.e("GJ", check);
//
//
//			}
//
//			@Override
//			public void onCompleted(Bundle bundle) {
//
//			}
//
//		}, 3000, true);
//
////		if (mainkey == null || mainkey.equals("") || pinValue == null || pinValue.equals("")) {
////			try {
////				json.put("code", -1);
////				json.put("message", "主密钥密文与校验值都不能为空");
////				callbackContext.error(json.toString());
//////				LogUtil.info("msg", "error");
////			} catch (JSONException e) {
////				e.printStackTrace();
////			}
////
////		} else {
////			Api api = new Api();
////			byte[] key = new byte[8];
////			api.UpdateMkey(mainkey, key);
////			// LogUtil.e("GGG", "mAIN获取出来的校验值"+ ByteTool.byte2hex(key));
////			try {
////				if (ByteTool.byte2hex(key).equals(pinValue)) {
////					json.put("Result", "更新主密钥成功");
////					api.Sys_writeSN(pinValue.trim().getBytes());
////					callbackContext.success(json.toString());
////				} else {
////					json.put("Result", "更新主密钥失败");
////					callbackContext.error(json.toString());
////				}
////			} catch (Exception e) {
////				// TODO: handle exception
////			}
////		}
//	}
//
//	/**
//	 * 读取设备编号
//	 *
//	 * @param callbackContext
//	 */
//	public void readDeviceNum(final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//        final JSONObject json = new JSONObject();
//        SiecomDevice.getCodeName(new DeviceCallback() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//                try {
//                    json.put("DeviceNumber", "读取失败");
//                    callbackContext.error(json.toString());
////                LogUtil.info("msg", "readDeviceNum:" + json.toString());
//                } catch (Exception e) {
//                    // TODO: handle exception
//                }
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//                try {
//                    json.put("DeviceNumber", bundle.getString("data"));
//                    callbackContext.success(json.toString());
////                LogUtil.info("msg", "readDeviceNum:" + json.toString());
//		        } catch (Exception e) {
//			// TODO: handle exception
//		        }
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//        }, 3000, true);
//
////		Api api = new Api();
////		byte[] key = new byte[20];
////		api.Sys_GetSNTwo(key);
////		JSONObject json = new JSONObject();
////
////		try {
////			json.put("DeviceNumber", new String(key).trim());
////			callbackContext.success(json.toString());
////			LogUtil.info("msg", "readDeviceNum:" + json.toString());
////		} catch (Exception e) {
////			// TODO: handle exception
////		}
//	}
//
//	/**
//	 * 写入设备编号
//	 *
//	 * @param deviceNum
//	 *            设备名称
//	 * @param callbackContext
//	 */
//	public void writeDeviceNum(String deviceNum, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//
//		final JSONObject json = new JSONObject();
//		if (deviceNum == null || deviceNum.equals("")) {
//			try {
//				json.put("code", -1);
//				json.put("message", "设备号不能为空");
//				callbackContext.error(json.toString());
////				LogUtil.info("msg", "error");
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//		} else {
//
//            SiecomDevice.setCodeName(deviceNum.trim(), new DeviceCallback() {
//                @Override
//                public void onStart() {
//
//                }
//
//                @Override
//                public void onError(Bundle bundle) {
//                    try {
//                        json.put("message", "写入设备号失败");
//                        callbackContext.success(json.toString());
//                    }catch (Exception e) {
//
//                    }
//                }
//
//                @Override
//                public void onSuccess(Bundle bundle) {
////                    Toast.makeText(DeviceActivity.this, "写入编号成功", Toast.LENGTH_SHORT).show();
//                    try {
//                        json.put("Result", "写入设备号成功");
//                        callbackContext.success(json.toString());
//                    }catch (Exception e) {
//
//			        }
//
//                }
//
//                @Override
//                public void onCompleted(Bundle bundle) {
//
//                }
//            }, 3000, true);
////			try {
////				Api api = new Api();
////				int is = api.Sys_writeSNTwo(deviceNum.getBytes());
////				if (is == 0) {
////					json.put("Result", "写入设备号成功");
////					callbackContext.success(json.toString());
////				} else {
////					json.put("message", "写入设备号失败");
////					callbackContext.error(json.toString());
////				}
////			} catch (Exception e) {
////				// TODO: handle exception
////			}
//		}
//	}
//
//	/**
//	 * 取消当前操作
//	 */
//	public void cancelOperation() {
//		// TODO Auto-generated method stub
//        SiecomDevice.cancelCurrentTask(new DeviceCallback() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//
//                Toast.makeText(mActivity, bundle.getString("data"), Toast.LENGTH_SHORT).show();
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//        }, 2000, true);
//	}
//
//	/**
//	 * 读取指纹特征码
//	 *
//	 * @param autoType
//	 * @param outTime
//	 *            超时时间设置
//	 * @return
//	 */
//	public void readFingerprint(int autoType, int outTime, CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// autoType = 0;
//		// bluetoochAdapterMgr();
//
//		if (autoType == FINGERMAS) {
//            readFingerPrint(outTime, autoType, callbackContext);
//		} else if (autoType == FINGERBITMAP) {
//			getfingerImg(outTime, autoType, callbackContext);
//		} else if (autoType == FINGERCP) {
//			readFingerPrinter(outTime, autoType, callbackContext);
//		}
//
//	}
//
//	private void getfingerImg(int outTime, final int autoType, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//
//        SiecomDevice.readFingerPic(new DeviceCallback() {
//            @Override
//            public void onStart() {
//
////                Snackbar.make(mLinearLayout, "您可以放开手指了,开始传输图像", Snackbar.LENGTH_LONG).setAction("Action", null).show();
//                Toast.makeText(mActivity,"您可以放开手指了,开始传输图像",Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
////                Snackbar.make(mLinearLayout, "指纹图片错误", Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//
//                int res = bundle.getInt("res");
//				JSONObject json = new JSONObject();
//				try {
//					if (res == 0) {
//						Bitmap bm = bundle.getParcelable("Img");
//						File externalStorageDirectory = Environment.getExternalStorageDirectory();
//						String path = externalStorageDirectory.getAbsolutePath() + "/ibrch/";
//						json.put("photo", Util.bitmapToStr(bm));
//						if (autoType == FINGERCP) {
//							json.put("finger", Finger);
//						}
//						json.put("res", 0);
//						Log.v("msg", "图片获取成功：" + json.toString());
////						LogUtil.info("msg", "success!!!!");
//						callbackContext.success(json.toString());
//						closeDialog();
//
//					} else if (res == 1) {
//						int progress = bundle.getInt("progress");
//						json.put("progress", progress);
//						json.put("res", 1);
//						// LogUtil.info("msg", "获取图像进度：" + progress + "%");
////						PluginResult mPlugin = new PluginResult(PluginResult.Status.OK, json.toString());
////						mPlugin.setKeepCallback(true);
//						// 进度返回
//						// callbackContext.sendPluginResult(mPlugin);
//
//					}
//				} catch (Exception e) {
//					// TODO: handle exception
//				}
//
//
////                dismissDialog();
////                /**
////                 * 获取到指纹特征码，默认使用Base64转一下
////                 */
////                dismissDialog();
////                Bitmap bm = bundle.getParcelable("Img");
////                View view = LayoutInflater.from(DeviceActivity.this).inflate(R.layout.fingerprintimage, null);
////                ImageView fingerImageView = (ImageView) view.findViewById(R.id.fingerImageView);
////                fingerImageView.setImageBitmap(bm);
////                pDialog = new MaterialDialog.Builder(DeviceActivity.this)
////                        .theme(Theme.DARK)
////                        .customView(view, true)
////                        .title("指纹图片")
////                        .positiveText("指纹图片")
////                        .onPositive(new MaterialDialog.SingleButtonCallback() {
////                            @Override
////                            public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
////                                pDialog.dismiss();
////                            }
////                        })
////                        .build();
////                pDialog.show();
////
////                Snackbar.make(mLinearLayout, "总耗时：" + (System.currentTimeMillis() - now) + "ms", Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//        }, outTime, true);
//
////		SiecomTask.TaskCallback taskCallback = new SiecomTask.TaskCallback() {
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				// TODO Auto-generated method stub
////				int res = bundle.getInt("res");
////				JSONObject json = new JSONObject();
////				try {
////					if (res == 0) {
////						Bitmap bm = bundle.getParcelable("Img");
////						File externalStorageDirectory = Environment.getExternalStorageDirectory();
////						String path = externalStorageDirectory.getAbsolutePath() + "/ibrch/";
////						json.put("photo", Util.bitmapToStr(bm));
////						if (autoType == FINGERCP) {
////							json.put("finger", Finger);
////						}
////						json.put("res", 0);
////						LogUtil.v("msg", "图片获取成功：" + json.toString());
////						LogUtil.info("msg", "success!!!!");
////						callbackContext.success(json.toString());
////						closeDialog();
////
////					} else if (res == 1) {
////						int progress = bundle.getInt("progress");
////						json.put("progress", progress);
////						json.put("res", 1);
////						// LogUtil.info("msg", "获取图像进度：" + progress + "%");
////						PluginResult mPlugin = new PluginResult(PluginResult.Status.OK, json.toString());
////						mPlugin.setKeepCallback(true);
////						// 进度返回
////						// callbackContext.sendPluginResult(mPlugin);
////
////					}
////				} catch (Exception e) {
////					// TODO: handle exception
////				}
////			}
////
////			@Override
////			public void onStart(Bundle bundle) {
////				// TODO Auto-generated method stub
////
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				// TODO Auto-generated method stub
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					closeDialog();
////					LogUtil.info("msg", "error");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		};
////		SiecomDevice.ReadFingerbitmap(taskCallback, outTime);
//	}
//
//    /**
//     * 读取指纹特征码
//     */
//    public void readFingerPrint(final int outTime, final int autoType, final CallbackContext callbackContext) {
//        SiecomDevice.readFingerFeature(new DeviceCallback() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//                /**
//                 * 获取到指纹特征码，默认使用Base64转一下
//                 */
//                String fingerCode = bundle.getString("data");
//                byte[] data = Base64.decodeBase64(fingerCode);
//                long finish = System.currentTimeMillis();
//                if (autoType == FINGERCP) {
//                    Finger = FingerUnit.parseWellcom(data);
//                    getfingerImg(outTime, autoType, callbackContext);
//                } else {
//                    JSONObject json = new JSONObject();
//                    try {
//                        // json.put("data",data);
//                        json.put("time", (finish - startTime));
//                        json.put("finger", FingerUnit.parseWellcom(data));
//                        String str = json.toString();// 将json对象转换为字符串
//                        callbackContext.success(str);
//                        closeDialog();
////                        LogUtil.info("msg", str);
//                    } catch (JSONException e) {
//                        e.printStackTrace();
//                    }
//                }
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//        }, 30000, true);
//
//    }
//
//
//	private void readFingerPrinter(final int outTime, final int autoType, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//        SiecomDevice.readFingerPic(new DeviceCallback() {
//            @Override
//            public void onStart() {
//
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//                int code = bundle.getInt("code");
//                String msg = bundle.getString("message");
//                JSONObject json = new JSONObject();
//				try {
//					json.put("code", code);
//					json.put("message", msg);
//					callbackContext.error(json.toString());
//					closeDialog();
////					LogUtil.info("msg", "error");
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//
//                Bitmap bm = bundle.getParcelable("Img");
//                String fingerCode = bundle.getString("data");
//				File mFile = new File("sdcard/a.jpeg");
//				try {
//
//					File mFiles = new File("sdcard/a.bmp");
//					FileOutputStream mFileOutputStream = new FileOutputStream(mFiles);
//					bm.compress(Bitmap.CompressFormat.JPEG,100,mFileOutputStream);
//				}catch (Exception e){
//
//				}
//
//
//				/**
//                 //				 * 获取到指纹特征码，默认使用Base64转一下
//                 //				 */
//				byte[] data = Base64.decodeBase64(fingerCode);
//				long finish = System.currentTimeMillis();
//                final JSONObject json = new JSONObject();
//				if (autoType == FINGERCP) {
//					Finger = FingerUnit.parseWellcom(data);
//
////                    Bitmap bm = bundle.getParcelable("Img");
//                    File externalStorageDirectory = Environment.getExternalStorageDirectory();
//                    String path = externalStorageDirectory.getAbsolutePath() + "/ibrch/";
//                    try {
//                        json.put("photo", Util.bitmapToStr(bm));
//						json.put("finger", Finger);
//                        json.put("res", 0);
////						JSONObject mJs = new JSONObject(json.toString());
////						LogUtil.e("GJ","取出指纹特征码"+mJs.get("finger"));
//                    }catch (JSONException e){
//
//                    }
//                    Log.v("msg", "图片获取成功：" + json.toString());
////						LogUtil.info("msg", "success!!!!");
//
//                    callbackContext.success(json.toString());
//                    closeDialog();
//
////					getfingerImg(outTime, autoType, callbackContext);
//
//				} else {
//
//					try {
//						// json.put("data",data);
//						json.put("time", (finish - startTime));
//						json.put("finger", FingerUnit.parseWellcom(data));
//						String str = json.toString();// 将json对象转换为字符串
//						callbackContext.success(str);
//						closeDialog();
////						LogUtil.info("msg", str);
//					} catch (JSONException e) {
//						e.printStackTrace();
//					}
//				}
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//        }, outTime, false);
//
////		SiecomDevice.ReadFinger(Config.SHENGYE_FINGER, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				startTime = System.currentTimeMillis();
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				/**
////				 * 获取到指纹特征码，默认使用Base64转一下
////				 */
////				String fingerCode = bundle.getString("data");
////				byte[] data = Base64.decodeBase64(fingerCode);
////				long finish = System.currentTimeMillis();
////				if (autoType == FINGERCP) {
////					Finger = FingerUnit.parseWellcom(data);
////					getfingerImg(outTime, autoType, callbackContext);
////				} else {
////					JSONObject json = new JSONObject();
////					try {
////						// json.put("data",data);
////						json.put("time", (finish - startTime));
////						json.put("finger", FingerUnit.parseWellcom(data));
////						String str = json.toString();// 将json对象转换为字符串
////						callbackContext.success(str);
////						closeDialog();
//////						LogUtil.info("msg", str);
////					} catch (JSONException e) {
////						e.printStackTrace();
////					}
////				}
////
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					closeDialog();
////					LogUtil.info("msg", "error");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		}, outTime);
//	}
//
//	/**
//	 * 灌入主密钥
//	 *
//	 * @param ComponentsOne
//	 *            分量一
//	 * @param ComponentsTwo
//	 *            分量二
//	 * @param callbackContext
//	 */
//	public void inputMainKey(String ComponentsOne, String ComponentsTwo, String deviceNum, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//        setEncrypt();
//		/*
//		 * byte[] key = new byte[20]; api.Sys_GetSNTwo(key); String deviceNum =
//		 * key.toString();
//		 */
//
//        if (ComponentsOne == null || ComponentsOne.equals("") || ComponentsTwo == null || ComponentsTwo.equals("")) {
//            JSONObject json = new JSONObject();
//            try {
//                json.put("code", -1);
//                json.put("message", "分量不能为空");
//                callbackContext.error(json.toString());
//            } catch (JSONException e) {
//                e.printStackTrace();
//            }
//            return;
//        }
//
//		if (deviceNum != null && !deviceNum.equals("")) {
//			// writeDeviceNum(DeviceNum,callbackContext);
//            writeDeviceNum(deviceNum,new CallbackContext(){
//
//            });
////			Api api = new Api();
////			api.Sys_writeSNTwo(deviceNum.getBytes());
//		}
//		int keyindex = 0;// 使用第0组存储密钥；
//
//
//        byte[] keys = EncryptUnit.exclusive(ComponentsOne, ComponentsTwo);
//
//        SiecomDevice.inputMainKey("01", ByteTool.byte2hex(keys),ConstDefine.KEY_3DES,0x00, new DeviceCallback() {
//            @Override
//            public void onStart() {
////                Snackbar.make(view, getResources().getString(R.string.input_key_start), Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//                JSONObject json = new JSONObject();
//				try {
//					int code = bundle.getInt("code");
//					String msg = bundle.getString("message");
//					json.put("code", code);
//					json.put("message", msg);
//					json.put("encryptType",ConstDefine.KEY_3DES);
//					callbackContext.error(json.toString());
////					LogUtil.info("msg", "error");
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
////                Snackbar.make(view, "err:" + code + "--" + msg, Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
////                Snackbar.make(view, getResources().getString(R.string.input_main_succ), Snackbar.LENGTH_LONG).setAction("Action", null).show();
//                JSONObject json = new JSONObject();
//				try {
//					json.put("result", "注入主密钥成功!");
//					callbackContext.success(json.toString());
////					LogUtil.info("msg", "注入主密钥成功");
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//
//        }, 3000, true);
//
////		LogUtil.info("msg", ByteTool.byte2hex(keys));
////		SiecomDevice.inputMainKey(keyindex, keys, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				startTime = System.currentTimeMillis();
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					json.put("result", "注入主密钥成功!");
////					callbackContext.success(json.toString());
////					LogUtil.info("msg", "注入主密钥成功");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					LogUtil.info("msg", "error");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		});
//	}
//
//	/**
//	 * 灌入工作密钥
//	 *
//	 * @param workKeyOne
//	 *            第一个工作密钥
//	 * @param workKeyTwo
//	 *            第二个工作密钥
//	 * @param callbackContext
//	 */
//	public void inputWorkKey(String workKeyOne, final String workKeyTwo, final CallbackContext callbackContext) {
//		// TODO Auto-generated method stub
//		// bluetoochAdapterMgr();
//        setEncrypt();
//		JSONArray workKeys = new JSONArray();
//		try {
//			workKeys.put(1, workKeyOne);
//			workKeys.put(2, workKeyTwo);
////			LogUtil.info("msg", workKeys.getString(0) + "--" + workKeys.getString(1) + "--" + workKeys.toString());
//			if (workKeys.getString(1) != null && !workKeys.getString(1).equals("")) {
//				keyindex = 1;
//				inputWorkKey(workKeys, workKeys.getString(keyindex), keyindex, callbackContext);
////				LogUtil.info("msg", "keyindex:" + workKeys.getString(keyindex));
//			} else {
//				keyindex = 2;
//				inputWorkKey(workKeys, workKeys.getString(keyindex), keyindex, callbackContext);
////				LogUtil.info("msg", "keyindex:" + workKeys.getString(keyindex));
//			}
//		} catch (JSONException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//	}
//
//	public void inputWorkKey(final JSONArray args, String workKey, int index, final CallbackContext callbackContext) {
//		keyindex = index;// 使用第0组存储密钥；
//		String mainKeyIndex = "01";// 对应的主密钥索引，参考之前注入的主密钥使用第0组
//
//		if (workKey == null || workKey.length() == 0) {
//			JSONObject json = new JSONObject();
//			try {
////				LogUtil.info("msg", "工作密钥不能为空");
//				json.put("code", -1);
//				json.put("message", "工作密钥不能为空");
//				callbackContext.error(json.toString());
////				LogUtil.info("msg", "error");
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
//			return;
//		}
//		Log.e("GJ","数据为："+mainKeyIndex + "index:"+"0"+index+"---:"+workKey);
//        SiecomDevice.inputWorkKey(mainKeyIndex, "0"+index, workKey,ConstDefine.KEY_3DES,0x81, new DeviceCallback() {
//            @Override
//            public void onStart() {
////                Snackbar.make(view, getResources().getString(R.string.input_key_start), Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//
//                int code = bundle.getInt("code");
//                String msg = bundle.getString("message");
//
////                Snackbar.make(view, "err:" + code + "--" + msg, Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//				JSONObject json = new JSONObject();
//				keyindex++;
//				try {
//					if (keyindex < 3 && (args.getString(keyindex) != null && !args.getString(keyindex).equals(""))) {
//						inputWorkKey(args, args.getString(keyindex), keyindex, callbackContext);
//					} else {
//						json.put("result", "注入工作密钥成功!");
//						callbackContext.success(json.toString());
////						LogUtil.info("msg", "注入工作密钥成功");
//					}
//				} catch (JSONException e) {
//					// TODO Auto-generated catch block
//					try {
//						json.put("result", "返回JSON字符对象处理失败!");
//					} catch (JSONException e1) {
//						// TODO Auto-generated catch block
//						e1.printStackTrace();
//					}
//					callbackContext.success(json.toString());
////					LogUtil.info("msg", "返回JSON字符对象处理失败");
//				}
//
////                Snackbar.make(view, getResources().getString(R.string.input_work_succ), Snackbar.LENGTH_LONG).setAction("Action", null).show();
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//
//            }
//
//        }, 3000, true);
//
////		SiecomDevice.inputWorkKey(keyindex, mainKeyIndex, StringUtil.hexStringToBytes(workKey), new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				startTime = System.currentTimeMillis();
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				keyindex++;
////				try {
////					if (keyindex < 2 && (args.getString(keyindex) != null && !args.getString(keyindex).equals(""))) {
////						inputWorkKey(args, args.getString(keyindex), keyindex, callbackContext);
////					} else {
////						json.put("result", "注入工作密钥成功!");
////						callbackContext.success(json.toString());
////						LogUtil.info("msg", "注入工作密钥成功");
////					}
////				} catch (JSONException e) {
////					// TODO Auto-generated catch block
////					try {
////						json.put("result", "返回JSON字符对象处理失败!");
////					} catch (JSONException e1) {
////						// TODO Auto-generated catch block
////						e1.printStackTrace();
////					}
////					callbackContext.success(json.toString());
////					LogUtil.info("msg", "返回JSON字符对象处理失败");
////				}
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				try {
////					int code = bundle.getInt("code");
////					String msg = bundle.getString("message");
////					json.put("code", code);
////					json.put("message", msg);
////					callbackContext.error(json.toString());
////					LogUtil.info("msg", "error");
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		});
//
//	}
//
//	/**
//	 * 启动密码键盘
//	 *
//	 * @param cardNo
//	 *            卡号 不能为空
//	 * @param outTime
//	 *            超时时间设置
//	 * @param selectType
//	 *            选择工作密钥类型
//	 * @param callbackContext
//	 */
//	public void inputPassWord(String cardNo, int outTime, int selectType, final CallbackContext callbackContext) {
//		// bluetoochAdapterMgr();
//
//        setEncrypt();
//		// TODO Auto-generated method stub
//		if(selectType == 0)
//			selectType = 1;
//		else if(selectType == 1)
//			selectType = 2;
//		int keyindex = selectType;// 使用第0组密钥对；
//		int timeOut = outTime;// 输入超时时间
//		byte maxLen = 0x06;// 输入最大长度
//		final byte encryptType = 0x00;// 0x00 ANSI X9.8加密，0x03明文
//		final JSONObject json = new JSONObject();
//
//
//        SiecomDevice.startInputPwd(cardNo, "01", "0"+keyindex, ConstDefine.KEY_3DES, "06",0, new DeviceCallback() {
//            @Override
//            public void onStart() {
//
//            }
//
//            @Override
//            public void onError(Bundle bundle) {
//                int code = bundle.getInt("code");
//                String msg = bundle.getString("message");
//                try {
//                    json.put("code", -1);
//                    json.put("message", "已经取消输入");
//                    callbackContext.error(json.toString());
//                }catch (JSONException e){
//
//                }
//
////                if (code == ErrorDefine.CANCEL_INPUT) {
////                    click_input.setText("");
////                    Snackbar.make(view, getResources().getString(R.string.input_cancel), Snackbar.LENGTH_LONG).setAction("Action", null).show();
////                }
////                if (code == ErrorDefine.KEY_TIME_OUT) {
////                    click_input.setText("");
////                    Snackbar.make(view, getResources().getString(R.string.input_timeout), Snackbar.LENGTH_LONG).setAction("Action", null).show();
////                }
////                if (code == ErrorDefine.LENGTH_ERR) {
////                    click_input.setText("");
////                    Snackbar.make(view, getResources().getString(R.string.input_length), Snackbar.LENGTH_LONG).setAction("Action", null).show();
////                }
////
////                if (code == ErrorDefine.KEY_INPUT_ERR) {
////                    click_input.setText("");
////                    Snackbar.make(view, getResources().getString(R.string.input_err), Snackbar.LENGTH_LONG).setAction("Action", null).show();
////
////                }
//            }
//
//            @Override
//            public void onSuccess(Bundle bundle) {
//                int num = bundle.getInt("data");
//                StringBuffer buf = new StringBuffer();
//                for (int i = 0; i < num; i++)
//                    buf.append("*");
//
////                click_input.setText(buf.toString());
//
//            }
//
//            @Override
//            public void onCompleted(Bundle bundle) {
//                //  LogUtil.e("pwd:", bundle.getString("data"));
////                click_input.setText(bundle.getString("data"));
//                //						json.put("code", 0);
//						String pin = bundle.getString("data");
//                        try {
//                            if (encryptType == 0x00) {
//                                // x9.8加密
//                                json.put("password", pin);
////							LogUtil.info("msg", json.toString());
//                                callbackContext.success(json.toString());
//                            } else if (encryptType == 0x03) {
//                                // 明文
//                                json.put("password", pin);
////							LogUtil.info("TAG", json.toString());
//                                callbackContext.success(json.toString());
//                            }
//                        }catch (JSONException e){
//
//                        }
//
//
//                Log.e("GJ","密文返回："+ bundle.getString("data"));
//            }
//        }, outTime, 1,true);
//
//
////		SiecomDevice.getPin(keyindex, cardNo, amount, timeOut, maxLen, encryptType, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				LogUtil.info("msg", "onStart--");
////			}
////
////			@SuppressWarnings("unused")
////			@Override
////			public void onSucceed(Bundle bundle) {
////				LogUtil.info("msg", "onSucceed--");
////				try {
////					int op = bundle.getInt("option");
////					switch (op) {
////					case KeyBroadModule.OP_CANCEL:
////						json.put("code", -1);
////						json.put("message", "已经取消输入");
////						callbackContext.error(json.toString());
////						closeDialog();
////						LogUtil.info("TAG", "error");
////						break;
////					case KeyBroadModule.OP_FINISH:
////						json.put("code", 0);
////						byte[] pin = bundle.getByteArray("password");
////						if (encryptType == 0x00) {
////							// x9.8加密
////							json.put("password", ByteTool.byte2hex(pin));
////							LogUtil.info("msg", json.toString());
////							callbackContext.success(json.toString());
////						} else if (encryptType == 0x03) {
////							// 明文
////							json.put("password", new String(pin).trim());
////							LogUtil.info("TAG", json.toString());
////							callbackContext.success(json.toString());
////						}
////						closeDialog();
////						break;
////					case KeyBroadModule.OP_INPUTTING:
////						// 显示*号的个数
////						// LogUtil.i("TAG",
////						// "KeyBroadModule.OP_INPUTTING--");
////						// json.put("code", 1);
////						// int num = bundle.getInt("keyNum");
////						// StringBuffer buf = new StringBuffer();
////						// for (int i = 0; i < num; i++) {
////						// buf.append("*");
////						// }
////						// json.put("password", buf.toString());
////						// LogUtil.i("TAG", json.toString());
////						// PluginResult mPlugin = new
////						// PluginResult(PluginResult.Status.OK,json.toString());
////						// mPlugin.setKeepCallback(true);
////						// callbackContext.sendPluginResult(mPlugin);
////						// callbackContext.success(json.toString());
////						break;
////					default:
////						break;
////					}
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				JSONObject json = new JSONObject();
////				int code = bundle.getInt("code");
////				String msg = bundle.getString("message");
////				try {
////					if (code == -7009) {
////						json.put("message", "密码输入超时");
////					} else if (code == -880) {
////						json.put("message", "密码输入超时;连接断开");
////					} else {
////						json.put("message", msg);
////					}
////					json.put("code", -111);
////					json.put("message", "卡号不能为空");
////					callbackContext.error(json.toString());
////					closeDialog();
////					LogUtil.info("msg", "error:" + json.toString());
////				} catch (JSONException e) {
////					e.printStackTrace();
////				}
////			}
////		});
//	}
//
//	// 连接蓝牙
////	private void connectBluetooth(BluetoothDevice localBluetoothDevice) {
////		BluetoothDevice bluetoothDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(localBluetoothDevice.getAddress());
////		LogUtil.info("msg", bluetoothDevice.getName() + "----" + bluetoothDevice.getAddress());
////
////		LogUtil.info("msg", "连接蓝牙中。。。。");
////		SiecomDevice.connectToBtDevice(bluetoothDevice, new SiecomTask.TaskCallback() {
////			@Override
////			public void onStart(Bundle bundle) {
////				Message msg = new Message();
////				msg.what = MSG_CONNING;
////				mHandler.sendMessage(msg);
////			}
////
////			@Override
////			public void onSucceed(Bundle bundle) {
////				BluetoothStatus = true;
////				Message msg = new Message();
////				msg.what = MSG_CONNED;
////				mHandler.sendMessage(msg);
////			}
////
////			@Override
////			public void onError(Bundle bundle) {
////				BluetoothStatus = false;
////				Message msg = new Message();
////				msg.what = MSG_NOCONN;
////				mHandler.sendMessage(msg);
////			}
////		});
////
////	}
//
//	static class Util {
//
//		public static Object fromJsonToJava(JSONObject json, Class pojo) throws Exception {
//			// 首先得到pojo所定义的字段
//			Field[] fields = pojo.getDeclaredFields();
//			// 根据传入的Class动态生成pojo对象
//			Object obj = pojo.newInstance();
//			for (Field field : fields) {
//				// 设置字段可访问（必须，否则报错）
//				field.setAccessible(true);
//				// 得到字段的属性名
//				String name = field.getName();
//				// 这一段的作用是如果字段在JSONObject中不存在会抛出异常，如果出异常，则跳过。
//				try {
//					json.get(name);
//				} catch (Exception ex) {
//					continue;
//				}
//				if (json.get(name) != null && !"".equals(json.getString(name))) {
//					// 根据字段的类型将值转化为相应的类型，并设置到生成的对象中。
//					if (field.getType().equals(Long.class) || field.getType().equals(long.class)) {
//						field.set(obj, Long.parseLong(json.getString(name)));
//					} else if (field.getType().equals(String.class)) {
//						field.set(obj, json.getString(name));
//					} else if (field.getType().equals(Double.class) || field.getType().equals(double.class)) {
//						field.set(obj, Double.parseDouble(json.getString(name)));
//					} else if (field.getType().equals(Integer.class) || field.getType().equals(int.class)) {
//						field.set(obj, Integer.parseInt(json.getString(name)));
//					} else if (field.getType().equals(Date.class)) {
//						field.set(obj, Date.parse(json.getString(name)));
//					} else {
//						continue;
//					}
//				}
//			}
//			return obj;
//		}
//
//		public static JSONObject fromObjToJson(Object pojo) throws Exception {
//			JSONObject json = new JSONObject();
//			Class clz = pojo.getClass();
//			// 首先得到pojo所定义的字段
//			Field[] fields = clz.getDeclaredFields();
//			// 根据传入的Class动态生成pojo对象
////			LogUtil.info("msg", "fields.length======" + fields.length);
//			for (Field field : fields) {
//				// 设置字段可访问（必须，否则报错）
//				field.setAccessible(true);
//				// 得到字段的属性名
//				String name = field.getName();
//				// 这一段的作用是如果字段在JSONObject中不存在会抛出异常，如果出异常，则跳过。
//
//				if (field.getType() != null) {
//					// 根据字段的类型将值转化为相应的类型，并设置到生成的对象中。
//					if (field.getType().equals(Long.class) || field.getType().equals(long.class)) {
//						json.put(name, field.getLong(pojo));
//					} else if (field.getType().equals(String.class)) {
//						json.put(name, field.get(pojo));
//					} else if (field.getType().equals(Double.class) || field.getType().equals(double.class)) {
//						json.put(name, field.getDouble(pojo));
//					} else if (field.getType().equals(Integer.class) || field.getType().equals(int.class)) {
//						json.put(name, field.getInt(pojo));
//					} else if (field.getType().equals(Date.class)) {
//						json.put(name, field.get(pojo));
//					} else {
//						continue;
//					}
//				}
//			}
//			return json;
//		}
//
//		public static String bitmapToStr(Bitmap bmp) {
//			String bmpStr = null;
//			ByteArrayOutputStream output = new ByteArrayOutputStream();// 初始化一个流对象
//			bmp.compress(Bitmap.CompressFormat.PNG, 100, output);// 把bitmap100%高质量压缩
//																	// 到
//																	// output对象里
//			bmp.recycle();// 自由选择是否进行回收
//			byte[] result = output.toByteArray();// 转换成功了
//			bmpStr = Base64.encodeBase64String(result);
//			try {
//				output.close();
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//			return bmpStr;
//		}
//	}
//
//	@Override
//	public void closeDialog() {
//		// TODO Auto-generated method stub
//		Message msg = new Message();
//		msg.what = MSG_CLOSE;
//		mHandler.sendMessage(msg);
//	}
//
//	@Override
//	public String getAnimationPath(String type, int num) {
//		String path = "";
//		// TODO Auto-generated method stub
//		if (ACTION_READ_FINGER_PRINTER.equals(type)) {
//			path = "file:///android_asset/gif/Finger.gif";
//		} else if (ACTION_READ_CARD.equals(type)) {
//			switch (num) {
//			case 0:
//				path = "file:///android_asset/gif/ic_play.gif";
//				break;
//			case 1:
//				path = "file:///android_asset/gif/nfc_play.gif";
//				break;
//			case 2:
//				path = "file:///android_asset/gif/cika_play.gif";
//				break;
//			default:
//				path = "file:///android_asset/gif/nfc_play.gif";
//				break;
//			}
//		} else if (ACTION_READ_IDCARD.equals(type)) {
//			path = "file:///android_asset/gif/id_play.gif";
//		} else if (ACTION_STRAT_INPUT.equals(type)) {
//			path = "file:///android_asset/gif/password.gif";
//		}
//		return path;
//	}
//}
